use list::List;

#[test]
fn test_list() {
    let mut list = List::new();
    assert_eq!(list.pop(), None);

    list.push(1);
    list.push(2);
    list.push(3);

    assert_eq!(list.pop(), Some(3));
    assert_eq!(list.pop(), Some(2));

    list.push(4);
    list.push(5);

    assert_eq!(list.pop(), Some(5));
    assert_eq!(list.pop(), Some(4));
    assert_eq!(list.pop(), Some(1));
    assert_eq!(list.pop(), None);
}

#[test]
fn test_list_string() {
    let mut list: List<String> = List::new();
    assert_eq!(list.pop(), None);

    list.push("1".to_string());
    list.push("2".to_string());
    list.push("3".to_string());

    assert_eq!(list.pop(), Some("3".to_string()));
    assert_eq!(list.pop(), Some("2".to_string()));

    list.push("4".to_string());
    list.push("5".to_string());

    assert_eq!(list.pop(), Some("5".to_string()));
    assert_eq!(list.pop(), Some("4".to_string()));
    assert_eq!(list.pop(), Some("1".to_string()));
    assert_eq!(list.pop(), None);
}

#[test]
fn test_list_peek() {
    let mut list = List::new();

    assert_eq!(list.peek(), None);

    list.push(1);

    assert_eq!(list.peek(), Some(&1));

    list.push(2);
    assert_eq!(list.peek(), Some(&2));
    assert_eq!(list.peek_mut(), Some(&mut 2));
}

#[test]
fn test_list_iter() {
    let mut list = List::new();

    list.push(1);
    list.push(2);
    list.push(3);

    let mut it = list.into_iter();

    assert_eq!(it.next(), Some(3));
    assert_eq!(it.next(), Some(2));
    assert_eq!(it.next(), Some(1));
    assert_eq!(it.next(), None);
}
